<?php
        include_once '../includes/constants.php';
        include_once '../includes/functions.php';

        $partners=new partners;
        $partners->connection($host,$user,$pass,$db);



        $action    =trim($text1);
        $name      =trim($category);


          // echo $_GET['msg'];


           if($_GET['msg']!="")
           {
           //echo "inside";

            $msg1=$_GET['msg'];
           }

           else
           $msg="";


        if($action==!"")   // submit cheking
        {
             if($name=="")
             {
             $msg="Please Enter a valid Category  !!";
             }
             else if($action=="add")
             {
              $sql="insert into partners_category (cat_name) values('".addslashes($name)."')";
              mysql_query($sql);

              if(mysql_errno()=="0")
                {       $msg=stripslashes($name)." has been added to Category list !!";
                }
                else
                {
                 $msg=stripslashes($name)." is alredy exists in  Category list !!";
                }

             }



        }



      $sql ="SELECT cat_name from partners_category";
      $res=mysql_query($sql);


?>



<script language="javascript" type="text/javascript">
<!--

function add_onclick() {
document.f1.text1.value="add";
document.f1.submit();

}

function remove_onclick() {
document.f1.text1.value="remove"
document.f1.submit();
}

//-->
</script>



<form method="post" action="index.php?Act=category" id="f1" name="f1">
<input  type="hidden" id="text1" name="text1" value="" />
  <table border='0' cellpadding="0" cellspacing="0" style="BORDER-COLLAPSE: collapse" width="40%" id="AutoNumber3" class="tablehdbdr">
    <tr>
      	<td width="100%" colspan="5" class="tdhead">
      	<p align="center">Add or Remove Category</p></td>
    </tr>
    <tr>
     	<td width="100%" colspan="5" class="textred">
      	<p align="center">&nbsp;<?=stripslashes($msg)?></p></td>
    </tr>
    <tr>
      	<td width="2%">&nbsp;</td>
      	<td width="45%">Category </td>
      	<td width="3%"><b>:</b></td>
      	<td width="48%"><input name="category" size="21" id="category" value="" /></td>
      	<td width="2%">&nbsp;</td>
    </tr>
    <tr>
		  <td width="2%">&nbsp;</td>
		  <td width="45%">&nbsp;</td>
		  <td width="3%">&nbsp;</td>
		  <td width="48%">&nbsp;</td>
		  <td width="2%">&nbsp;</td>
    </tr>
	<tr>
		  <td width="50%" colspan="5" class="tdhead">
		  <p align="center"><input type="button" value="Add" name="B1" id="add" onclick="return add_onclick()" /></p></td>
    </tr>
  </table>
</form><br/><br/>
<form name="FormName" action="category_remove.php" method="post">
 <table border="0" cellpadding="0" cellspacing="0" style="BORDER-COLLAPSE: collapse" width="40%" id="AutoNumber2" class="tablehdbdr">
    <tr>
      <th width="301" colspan="4" height="20" class="tdhead"><p>Remove Category</p></th>
    </tr>
    <tr>
      <td width="301" colspan="4" height="20" class="textred" align="center">
      <?=stripslashes($msg1)?></td>
    </tr>
    <tr>
      <td width="12" height="30">&nbsp;</td>
      <td width="125" height="30">Category </td>
      <td width="257" height="30" align="left">
      <select size="1" name="categorycompo" id="select1">
      <option selected="selected" >Choose a Category</option>
      <?
      while($row = mysql_fetch_object($res))
               {
               if (trim($category)==trim($row->cat_name)) {
                    $var="selected='selected'";
               }
               else {
                    $var="";
               }
      ?>
               <option <?=$var?>> <?=$row->cat_name?> </option>
      <?
               }
      ?>

      </select></td>
    </tr>
    <tr>
      <td width="12" height="24">&nbsp;</td>
      <td width="125" height="24">&nbsp;</td>
      <td width="257" height="24">&nbsp;</td>
      <td width="9" height="24">&nbsp;</td>
    </tr>
    <tr>
      <td width="12" height="4"></td>
      <td width="125" height="4"></td>
      <td width="257" height="4"></td>
      <td width="7" height="4"></td>
    </tr>
    <tr>
      <th width="402" height="1" colspan="4" class="tdhead">
      <p align="center"><input type="submit" value="REMOVE" /></p>
      </th>
    </tr>
  </table>
  </form>
